import 'package:flutter/material.dart';
import 'package:core_package/core_package.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app_unionad/core/configuration.dart';
import 'package:flutter_app_unionad/request/login_request.dart';
import 'package:flutter_app_unionad/ui/basice/base_center_alert_widget.dart';
import 'package:flutter_app_unionad/ui/basice/input_separator_widget.dart';
import 'package:flutter_app_unionad/ui/basice/my_button.dart';
import 'package:flutter_app_unionad/view_model/change_device_event.dart';

//绑定设备
class WithdrawDepositWidget extends StatefulWidget {
  final TextInputType? keyboardKey;
  final String ?title;
  final Function(String value) ?onTap;
  final String ?buttonTitle;
  final bool? isBi;

  WithdrawDepositWidget({this.keyboardKey, this.title = '请输入兑换天数', this.onTap, this.buttonTitle = '确定', this.isBi});

  @override
  _WithdrawDepositWidgetState createState() => _WithdrawDepositWidgetState();
}

class _WithdrawDepositWidgetState extends State<WithdrawDepositWidget> with BaseCenterAlertWidget {
  String? device;

  @override
  Widget buildContent(BuildContext context) {
    return Column(
      children: [
        MySizeBox(height: 30),
        Text(
          widget.title??'',
          style: TextStyle(
            color: MyColors.color_27_27_27,
            fontSize: MyFont.font16,
            fontWeight: MyFontWeight.bold,
          ),
        ),
        MySizeBox(height: 10),
        Padding(
          padding: EdgeInsets.symmetric(horizontal: 69.px),
          child: InputSeparatorWidget(
            valueChange: (value) {
              device = value;
              if (widget.isBi==true) setState(() {});
            },
            title: "",
            keyboard: widget.keyboardKey ?? TextInputType.numberWithOptions(decimal: true),
            placeholder: "请输入",
            titleWidth: 0,
            inputFont: MyFont.font16,
          ),
        ),
        if (widget.isBi==true) MySizeBox(height: 10),
        if (widget.isBi==true) buildRow(),
        if (widget.isBi==true) MySizeBox(height: 10),
        if (widget.isBi==true)Text(
          '注：单次提现低于20，收取10%手续费',
          style: TextStyle(
            fontSize: MyFont.font12,
            color: MyColors.color_43_44_48,
          ),
        ),
        MySizeBox(height: widget.isBi==true?15.px:30.px),
        MyButton(
          title: widget.buttonTitle??'',
          radius: 1.px,
          onTap: () {
            if (widget.onTap != null) widget.onTap?.call(device??'');
          },
          width: 133.px,
        )
      ],
    );
  }

  Widget buildRow() {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 69.px),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              Text(
                '等于',
                style: TextStyle(
                  fontSize: MyFont.font12,
                  color: MyColors.color_43_44_48,
                ),
              ),
              SizedBox(
                width: 5.px,
              ),
              Text(
                device == null || device == '' ? "0" : '${(num.parse(device??'0') * 0.0001*0.9).toStringAsFixed(2)}',
                style: TextStyle(
                  fontSize: MyFont.font12,
                  color: MyColors.color_246_45_29,
                ),
              ),
              SizedBox(
                width: 5.px,
              ),
              Text(
                '元',
                style: TextStyle(
                  fontSize: MyFont.font14,
                  color: MyColors.color_43_44_48,
                ),
              ),
            ],
          ),
          Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              Text(
                '手续费',
                style: TextStyle(
                  fontSize: MyFont.font12,
                  color: MyColors.color_43_44_48,
                ),
              ),
              SizedBox(
                width: 5.px,
              ),
              Text(
                device == null || device == ''
                    ? '0'
                    : (num.parse(device??'0') * 0.0001 > 20 ? '  0' : '${(num.parse(device??'0') * 0.0001 *0.9 * 0.1).toStringAsFixed(2)}'),
                style: TextStyle(
                  fontSize: MyFont.font14,
                  color: MyColors.color_246_45_29,
                ),
              ),
              SizedBox(
                width: 5.px,
              ),
              Text(
                '元',
                style: TextStyle(
                  fontSize: MyFont.font12,
                  color: MyColors.color_43_44_48,
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return buildCloseAlertWidget(context, child: buildContent(context));
  }
}
